home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3247 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. From: graphics_addict@msn.com (Alan Armstrong)
  2. Subject: inline asm in member fn
  3. Date: 22 Jan 96 23:14:18 -0800
  4. Message-ID: <00001a81+000091f1@msn.com>
  5. Path: news.msn.com!msn.com
  6. Newsgroups: comp.lang.c++
  7. Organization: The Microsoft Network (msn.com)
  8.  
  9.  
  10. Hello, 
  11.  
  12.   I am getting an expression syntax error in the following member
  13. function.  The comiler points to the line marked with "->"
  14. My manual states that this is a catchall compile error.
  15. I have used this code in a standard function, and it has worked fine.
  16. The only caveats about the inline code I am aware of is that the
  17. 1st brace "{" must be on the same line as the keyword "asm" and
  18. the end of each instruction is signaled by a new line or semicolon.
  19. I commented out the line pointed to by the compiler and the code 
  20. compiled successfully, although it is useless without the line. 
  21.  
  22.  
  23. /***************************************************************
  24.  *                                                             *
  25.  * Screen::Fill_Screen()                                       *
  26.  *                                                             *
  27.  *     This function will fill the entire screen with the sent *
  28.  *     color.                                                  *
  29.  *                                                             *
  30.  * arguments                                                   *
  31.  *                                                             *
  32.  *     int(color): color to fill the screen with               *
  33.  *                                                             *
  34.  * returns: void                                               *
  35.  *                                                             *
  36.  ***************************************************************/
  37. void Screen::Fill_Screen(int color)
  38. {
  39. // use the inline assembler for speed
  40.     asm {
  41. ->      les di,video_buffer   // point es:di to video buffer
  42.       mov al,BYTE PTR color // move the color into al
  43.       mov ah,al             // replicate color into ah
  44.       mov cx,320*200/2      // number of words to fill
  45.                       // (using words is faster than bytes)
  46.       rep stosw             // move the color into the video
  47.                     // buffer really fast!
  48.     } // end inline asm
  49.  
  50. } // end Fill_Screen
  51.  
  52.  
  53. Here's the relevant part of the Screen class definition
  54.  
  55. class Screen {
  56.     protected:
  57.         unsigned char far *video_buffer;
  58.     public:
  59.         .
  60.         .
  61.         .
  62.     // paints the screen with color
  63.         void Fill_Screen(int color);
  64.         .
  65.         .
  66.         .
  67. };
  68.  
  69. Any help is greatly appreciated!
  70.  
  71. Thanks,
  72.  
  73. Alan <graphics_addict@msn.com>
  74.